#define  _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <memory>
using namespace std;

template<class T>
class SmartPtr
{
public:
	SmartPtr(T* ptr = nullptr)
		:_ptr(ptr)
	{}

	~SmartPtr()
	{
		if (_ptr)
			delete _ptr;
	}

	T& operator*()
	{
		return *_ptr;
	}

	T* operator->()
	{
		return _ptr;
	}
private:
	T* _ptr;
};

struct Date
{
	int _year = 1;
	int _month = 1;
	int _day = 1;
};

template<class T>
class DeleteArray
{
public:
	void operator()(T* ptr)
	{
		delete[] ptr;
	}
};

class Fclose
{
public:
	void operator()(FILE* pf)
	{
		cout << "void operator()(FILE* pf)" << endl;
		fclose(pf);
	}
};

int main1()
{
	shared_ptr<Date> up1(new Date[5], DeleteArray<Date>());
	shared_ptr<FILE> up2(fopen("text.txt", "w"), Fclose());
	
	shared_ptr<Date> up3 = make_shared<Date>(2024, 10, 24);

	return 0;
}


#include "shared_ptr.h"

int main2()
{
	yjz::shared_ptr<Date> sp1(new Date);
	yjz::shared_ptr<Date> sp2(sp1);

	yjz::shared_ptr<Date> sp3(new Date);
	sp1 = sp3;

	return 0;
}

struct ListNode
{
	int _data;
	weak_ptr<ListNode> _next;
	weak_ptr<ListNode> _prev;
};

int main()
{
	shared_ptr<ListNode> n1(new ListNode);
	shared_ptr<ListNode> n2(new ListNode);

	n1->_next = n2;
	n2->_prev = n1;

	return 0;
}